package assignmentonepenguins



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Customer)
class CustomerTests {

    void test_RequiredFields() {
        // Test missing required fields (C-1)
        Customer c = new Customer()
        assert !c.validate()

        // Test all required fields present - NOTE: Created Date field is implicit (C-1)
        // Test valid password length (C-4)
        c.setEmail("email@email.com")
        c.setPassword("ggggrrr")
        assert c.validate()

    }

    void test_EmailAddress() {
        // Test invalid email form (C-3)
        Customer c = new Customer()
        c.setEmail("emailemail.com")
        c.setPassword("ggggrrr")
        assert !c.validate()
        assert c.hasErrors()

        c.setEmail("email@.com")
        assert !c.validate()
        assert c.hasErrors()

        c.setEmail("email@email@email.com")
        assert !c.validate()
        assert c.hasErrors()

        c.setEmail("email@email.com.com")
        assert !c.validate()
        assert c.hasErrors()

        c.setEmail("!#!#@email.com.com")
        assert !c.validate()
        assert c.hasErrors()

        // Test valid email form (C-3)
        c.setEmail("email@email.com")
        assert c.validate()
        assert !c.hasErrors()
    }

    void test_InvalidPassword() {
        // Test password < 6 chars (C-4)
        Customer c = new Customer()
        c.setEmail("email@email.com")
        c.setPassword("ggrrr")
        assert !c.validate()
        assert c.hasErrors()

        // Test password > 8 chars (C-4)
        c.setPassword("ggggrrrrr")
        assert !c.validate()
        assert c.hasErrors()
    }
}
